<template>
  <div class="head">
    <div class="title">业务量统计报表</div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form ref="form" :rules="rules" style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;" :model="form" label-width="80px">
            <el-form-item style="margin-left: 0;" class="text" label="网点">
              <el-select v-model="form.region" class="input" :disabled="true" placeholder="辽宁盘锦公司" />
            </el-form-item>
            <el-form-item class="text" label="汇总级别" prop="collectType">
              <el-select v-model="form.collectType" class="input" placeholder="请选择">
                <el-option label="时间段" value="1" />
                <el-option label="天" value="2" />
              </el-select>
            </el-form-item>
            <el-form-item class="text" label="日期" prop="Time">
              <el-date-picker v-model="form.Time" class="input1" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="changeTime" />
            </el-form-item>
            <div>
              <el-form-item>
                <el-button type="primary" @click="Inquire">查询</el-button>
                <elbutton :obj="form" @dj="khClear" />
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form ref="form1" style="display: flex;justify-content: space-between;flex-wrap: wrap;" :model="form" label-width="80px">
            <div style="display: flex;flex-wrap: wrap;justify-content: space-between;width: 745px;">
              <el-form-item class="text" style="margin-left: 0;" label="展示级别">
                <el-select v-model="form.level" class="input" placeholder="请选择">
                  <el-option label="网点" value="1" />
                  <el-option label="承包区" value="2" />
                </el-select>
              </el-form-item>

            </div>
            <div>
              <el-form-item>
                <el-button><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <elltable :loading="loading" :data="tableData" :th="th" :n="5" />

        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <pagination :current-page="current" :page-sizes="[10, 20, 30, 40]" :page-size="10" layout="total, prev, pager, next" :total="total" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
          </div>
        </div>

      </el-col>
    </el-row>
  </div>
</template>

<script>
import { PaidPiecesApi } from '@/api/HqFinancePanel'

export default {

  components: {},
  data() {
    return {
      rules: {
        Time: [
          { required: true, message: '请选择时间', trigger: 'change' }
        ],
        collectType: [
          { required: true, message: '请选择汇总级别', trigger: 'change' }
        ]
      },
      loading: false,
      value1: [],
      form: {
        collectType: '',
        endTime: '',
        level: '',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        startTime: ''
      },
      th: [],
      tableData: [],
      current: 0, // 页数
      pages: 0, // 条数
      total: 0// 总数
    }
  },

  computed: {},

  created() { },

  methods: {
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.Inquire()
    },
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.Inquire()
    },
    // 序号
    table_index(index) {
      return (this.current - 1) * this.pages + index + 1
    },
    // 选择时间
    changeTime(value) {
      this.form.startTime = value[0]
      this.form.endTime = value[1]
    },
    // 查询
    async Inquire() {
      // if (this.form.startTime === '') {
      //   this.$message('请选择时间')
      //   return
      // }
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.loading = true

          const res = await PaidPiecesApi(this.form)
          console.log('查询', res)
          this.loading = false

          if (res.code === 200) {
            this.tableData = res.data.list.data
            this.current = res.data.list.current
            this.total = res.data.list.total
            this.pages = res.data.list.pages
            this.th = res.data.fields
          } else {
            this.tableData = []
            this.current = 1
            this.total = 0
            this.pages = 10
            this.th = []
          }
        }
      })
    },
    // 重置
    khClear(aaa) {
      this.form = aaa
    }
  }
}

</script>
<style
  scoped
  lang="scss"
>
.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  // display: flex;
  // justify-content: space-between;
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    // margin-left: 52px;
    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      // border: 1px solid #B4B4B4;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border: 1px solid #b4b4b4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
